$(function(){
//	getDataById(root + 'cms/fanliRules/findFanliRulesById',"#fanliRulesTmpl","#fanliRulesContent");
	$("#saveOrupdate").click(function(){
		saveData(root + 'cms/fanliRules/saveFanliRules','fanliRulesList.jsp');
	});
	var tId = getUrlParam("id");
	if (!tId) {
		myAlert('id参数不能为空');
		return;
	}
	$.ajax({
		url : root + 'cms/fanliRules/findFanliRulesById',
		type : 'post',
		dataType : 'json',
		data : {
			modelId : tId
		},
		success : function(data) {
			if (data.code == 1) {
			console.log(data.object)
			
				var contentHtml = $('#fanliRulesTmpl').render(data.object, {
					mydata : data
				});
				$('#fanliRulesContent').html(contentHtml);
				
				//填充数据 start
				var nameList = data.object.fanliBusiness;
				var optionHtml = '';
				for (var i = 0; i < data.object.fanliBusiness.length; i++) {
					var busName = nameList[i].businessName;
					var id = nameList[i].id;
					if(data.object.fanliRules.busId == data.object.fanliBusiness[i].id ){
						optionHtml += "<option value ='"+id + "' selected>" + busName + "</option>";
					}else{
						optionHtml += "<option value ='"+id+"'>"+busName+"</option>";
					}
				}
				$('#busId').html(optionHtml);
				//填充数据  end
				
			}else{
				var contentHtml = $('#fanliRulesTmpl').render("");
				$('#fanliRulesContent').html(contentHtml);
			}
		}
	});
});